home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
os2
/
pccts.zip
/
PRED.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-08
|
5KB
|
201 lines
/*
* pred.c -- source for predicate detection, manipulation
*
* SOFTWARE RIGHTS
*
* We reserve no LEGAL rights to the Purdue Compiler Construction Tool
* Set (PCCTS) -- PCCTS is in the public domain. An individual or
* company may do whatever they wish with source code distributed with
* PCCTS or the code generated by PCCTS, including the incorporation of
* PCCTS, or its output, into commerical software.
*
* We encourage users to develop software with PCCTS. However, we do ask
* that credit is given to us for developing PCCTS. By "credit",
* we mean that if you incorporate our source code into one of your
* programs (commercial product, research project, or otherwise) that you
* acknowledge this fact somewhere in the documentation, research report,
* etc... If you like PCCTS and have developed a nice tool with the
* output, please mention that you developed it using PCCTS. In
* addition, we ask that this header remain intact in our source code.
* As long as these guidelines are kept, we expect to continue enhancing
* this system and expect to make other tools available as they are
* completed.
*
* ANTLR 1.06
* Terence Parr
* Purdue University
* 1989-1992
*/
#include <stdio.h>
#include "set.h"
#include "syn.h"
#include "hash.h"
#include "generic.h"
#include "dlgdef.h"
/* Look for a predicate;
*
* Do not pass anything but Junction nodes; no Actions, Tokens, RuleRefs.
* Return the predicate found if any. ONLY FINDS ONE FOR NOW.
*/
Predicate
find_predicates(alt)
Node *alt;
{
#ifdef DBG_PRED
Junction *j;
RuleRefNode *r;
TokNode *t;
#endif
Junction *pr;
Predicate pred;
static Predicate pred_empty = {NULL,NULL};
int max_k=0;
if ( alt==NULL ) return pred_empty;
#ifdef DBG_PRED
switch ( alt->ntype )
{
case nJunction :
j = (Junction *) alt;
fprintf(stderr, "Junction(in %s)", j->rname);
switch ( j->jtype )
{
case aSubBlk :
fprintf(stderr,"aSubBlk\n");
break;
case aOptBlk :
fprintf(stderr,"aOptBlk\n");
break;
case aLoopBegin :
fprintf(stderr,"aLoopBeginBlk\n");
break;
case aLoopBlk :
fprintf(stderr,"aLoopBlk\n");
break;
case aPlusBlk :
fprintf(stderr,"aPlusBlk\n");
break;
case EndBlk :
fprintf(stderr,"EndBlk\n");
break;
case RuleBlk :
fprintf(stderr,"RuleBlk\n");
break;
case Generic :
fprintf(stderr,"Generic\n");
break;
case EndRule :
fprintf(stderr,"EndRule\n");
break;
}
break;
case nRuleRef :
r = (RuleRefNode *) alt;
fprintf(stderr, "RuleRef(in %s)\n", r->rname);
break;
case nToken :
t = (TokNode *) alt;
fprintf(stderr, "TokenNode(in %s)%s\n", t->rname, TokenStr[t->token]);
break;
case nAction :
fprintf(stderr, "Action\n");
break;
}
#endif
switch ( alt->ntype )
{
case nJunction :
{
Predicate a;
Junction *p = (Junction *) alt;
if ( p->jtype == EndRule )
{
return pred_empty;
}
if ( p->jtype==aLoopBlk || p->jtype==RuleBlk ||
p->jtype==aPlusBlk || p->jtype==EndRule )
{
require(p->pred_lock!=NULL, "rJunc: lock array is NULL");
if ( p->pred_lock[1] )
{
return pred_empty;
}
p->pred_lock[1] = TRUE;
}
a = find_predicates(p->p1);
if ( a.expr!=NULL )
{
if ( p->jtype==aLoopBlk || p->jtype==RuleBlk ||
p->jtype==aPlusBlk || p->jtype==EndRule )
{
p->pred_lock[1] = FALSE;
}
return a;
}
a = find_predicates(p->p2);
if ( p->jtype==aLoopBlk || p->jtype==RuleBlk ||
p->jtype==aPlusBlk || p->jtype==EndRule )
{
p->pred_lock[1] = FALSE;
}
return a;
}
case nAction :
{
set f;
ActionNode *p = (ActionNode *) alt;
if ( p->init_action ) return find_predicates(p->next);
if ( p->is_predicate )
{
set rk;
Tree *t;
#ifdef DBG_PRED
fprintf(stderr, "action: <<%s>>?\n", p->action);
#endif
#ifdef COMPUTE_CONTEXT
ConstrainSearch = 0;
TRAV(p->next, LL_k, &rk, t);
t = tshrink( t );
t = tflatten( t );
t = tleft_factor( t );
#ifdef DBG_PRED
fprintf(stderr, "after shrink&flatten&left_factor:"); preorder(t); fprintf(stderr, "\n");
#endif
#endif
pred.expr = p->action;
#ifdef COMPUTE_CONTEXT
pred.context = t;
#else
pred.context = NULL;
#endif
return pred;
}
return pred_empty;
}
case nRuleRef :
{
Predicate a;
RuleRefNode *p = (RuleRefNode *) alt;
Junction *r;
int save_halt;
RuleEntry *q = (RuleEntry *) hash_get(Rname, p->text);
r = RulePtr[q->rulenum];
save_halt = r->end->halt;
r->end->halt = TRUE;
a = find_predicates((Node *)r->p1);
r->end->halt = save_halt;
return a;
}
case nToken :
break;
}
return pred_empty;
}